// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Money from "./Money";
import {colliderGroup} from "./HeroContact";
import ControlScript from "../PublicScript/ControlScript";
import GameControl_red_blue_man from "./GameControl_red_blue_man";
import Music, {musicName} from "../PublicScript/Music";

const {ccclass, property} = cc._decorator;

@ccclass
export default class CoinControl extends cc.Component {

    // LIFE-CYCLE CALLBACKS:

    label = null;

    // onLoad () {}

    start () {
        this.node.angle = -30;
        this.label = this.node.children[0];
        this.anim();
        this.scaleAnim();
    }

    onBeginContact(contact, self, other) {
        Music.GamePlayEffect(musicName.Diamond_Sound);
         if(other.node.group == colliderGroup.hero && other.tag == 0){
             this.node.active = false;
             GameControl_red_blue_man.coinNum ++;
             ControlScript.instantiate("coinNum", (res)=>{
                 res.setPosition(this.node.position)
             });
         }
    }

    //动画
    anim(){
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.rotateTo(0.3, 30),
                    cc.rotateTo(0.3, 0),
                    cc.rotateTo(0.3, -30),
                    cc.rotateTo(0.3, 0),
                )
            )
        )
    }

    scaleAnim(){
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.scaleTo(0.3, 1.2),
                    cc.scaleTo(0.3, 1)
                )
            )
        )
    }



    // update (dt) {}
}
